--- /dev/null
+BEGIN {
+ n = 0
+ sel = 0
+ FS=":"
+}
+($3 == "category") && (categories !~ /:$4:/) {
+ categories = categories ":" $4 ":";
+ n++
+ if ($4 ~ "^" selected "$") sel = n
+ c[n] = $4
+ if (f[$4] == "") f[$4] = rootdir "/" indexpage "?cat=" $4
+}
+($3 == "name") && ((p[$4] == 0) || (p[$4] > int($5))) {
+ gsub(/^.*\//, "", $1);
+ p[$4] = int($5)
+ f[$4] = rootdir "/" $1
+}
+END {
+ print "<div id=\"mainmenu\"><h3><strong>Categories:</strong></h3><ul>"
+
+ for (i = 1; i <= n; i++) {
+ if (sel == i) print "<li class=\"selected-maincat\"><a href=\"" f[c[i]] "\">»" c[i] "«</a></li>"
+ else print "<li><a href=\"" f[c[i]] "\"> " c[i] " </a></li>";
+ }
+
+ print "</ul></div>"
+}
--- /dev/null
+function start_form(title, field_opts) {
+ print "<div class=\"settings\">"
+ if (title != "") print "<div class=\"settings-title\"><h3><strong>" title "</strong></h3></div>"
+ print "<div class=\"settings-content\">"
+}
+
+function end_form(form_help, form_help_link) {
+ print "</div>"
+ if (form_help != "") form_help = "<dl>" form_help "</dl>"
+ print "<div class=\"settings-help\"><blockquote><h3><strong>Short help:</strong></h3>" form_help form_help_link "</blockquote></div>"
+ print "<div style=\"clear: both\"> </div></div>"
+}
--- /dev/null
+BEGIN {
+ FS="[ \t]"
+ print "<form enctype=\"multipart/form-data\" method=\"post\">"
+ start_form("Static IP addresses (for DHCP)")
+ print "<table width=\"70%\" summary=\"Settings\">"
+ print "<tr><th>MAC address</th><th>IP</th><th></th></tr>"
+}
+
+# only for valid MAC addresses
+($1 ~ /^[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]$/) {
+ gsub(/#.*$/, "");
+ print "<tr><td>" $1 "</td><td>" $2 "</td><td align=\"right\" width=\"10%\"><a href=\"" url "?remove_dhcp=1&remove_mac=" $1 "\">Remove</a></td></tr>"
+}
+
+END {
+ print "<tr><td><input type\"text\" name=\"dhcp_mac\" value=\"" mac "\" /></td><td><input type=\"text\" name=\"dhcp_ip\" value=\"" ip "\" /></td><td style=\"width: 10em\"><input type=\"submit\" name=\"add_dhcp\" value=\"Add\" /></td></tr>"
+ print "</table>"
+ print "</form>"
+ end_form();
+}
+
--- /dev/null
+BEGIN {
+ FS="[ \t]"
+ start_form("Hostnames")
+ print "<table width=\"70%\" summary=\"Settings\">"
+ print "<tr><th>IP</th><th>Hostname</th><th></th></tr>"
+ print "<tr><td colspan=\"3\"><hr class=\"separator\" /></td></tr>"
+}
+
+# only for valid IPv4 addresses
+($1 ~ /^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/) {
+ gsub(/#.*$/, "");
+ output = ""
+ names_found = 0
+ n = split($0, names, "[ \t]")
+ first = 1
+ for (i = 2; i <= n; i++) {
+ if (names[i] != "") {
+ if (first != 1) output = output "<tr>"
+ output = output "<td>" names[i] "</td><td align=\"right\" width=\"10%\"><a href=\"" url "?remove_host=1&remove_ip=" $1 "&remove_name=" names[i] "\">Remove</a></td></tr>"
+ first = 0
+ names_found++
+ }
+ }
+ if (names_found > 0) {
+ print "<tr><td rowspan=\"" names_found "\">" $1 "</td>" output
+ print "<tr><td colspan=\"3\"><hr class=\"separator\" /></td></tr>"
+ }
+}
+
+END {
+ print "<form enctype=\"multipart/form-data\" method=\"post\">"
+ print "<tr><td><input type\"text\" name=\"host_ip\" value=\"" ip "\" /></td><td><input type=\"text\" name=\"host_name\" value=\"" name "\" /></td><td style=\"width: 10em\"><input type=\"submit\" name=\"add_host\" value=\"Add\" /></td></tr>"
+ print "</form>"
+ print "</table>"
+ end_form()
+}
+
if ($3 != "") field_opts=" id=\"" $3 "\""
else field_opts=""
if ($4 == "hidden") field_opts = field_opts " style=\"display: none\""
- print "<div class=\"settings\"" field_opts ">"
- if ($2 != "") print "<div class=\"settings-title\"><h3><strong>" $2 "</strong></h3></div>"
- print "<div class=\"settings-content\"><table width=\"100%\" summary=\"Settings\">"
+ start_form($2, field_opts);
+ print "<table width=\"100%\" summary=\"Settings\">"
form_help = ""
form_help_link = ""
}
$1 ~ /^end_form/ {
if (field_open == 1) print "</td></tr>"
field_open = 0
- print "</table></div>"
- if (form_help != "") form_help = "<dl>" form_help "</dl>"
- print "<div class=\"settings-help\"><blockquote><h3><strong>Short help:</strong></h3>" form_help form_help_link "</blockquote></div>"
+ print "</table>"
+ end_form(form_help, form_help_link);
form_help = ""
form_help_link = ""
- print "<div style=\"clear: both\"> </div></div>"
}
--- /dev/null
+BEGIN {
+ FS=":"
+ print "<div id=\"submenu\"><h3><strong>Sub-Categories:</strong></h3><ul>"
+}
+{
+ if ($5 ~ "^" selected "$") print "<li class=\"selected-maincat\"><a href=\"" rootdir "/" $6 "\">»" $5 "«</a></li>"
+ else print "<li><a href=\"" rootdir "/" $6 "\"> " $5 " </a></li>"
+}
+END {
+ print "</ul></div>"
+}
+
rootdir=/cgi-bin/webif
indexpage=index.sh
+# workarounds for stupid busybox fork/exec on [ ]
+empty() {
+ case "$1" in
+ "") return 0 ;;
+ *) return 255 ;;
+ esac
+}
+equal() {
+ case "$1" in
+ "$2") return 0 ;;
+ *) return 255 ;;
+ esac
+}
+
categories() {
- grep '##WEBIF:' $cgidir/.categories $cgidir/*.sh 2>/dev/null | awk -F: '
- BEGIN {
- n = 0
- sel = 0
- }
- ($3 == "category") && (categories !~ /:$4:/) {
- categories = categories ":" $4 ":";
- n++
- if ($4 ~ /^'"$1"'$/) sel = n
- c[n] = $4
- if (f[$4] == "") f[$4] = "'"$rootdir/$indexpage"'?cat=" $4
- }
- ($3 == "name") && ((p[$4] == 0) || (p[$4] > int($5))) {
- gsub(/^.*\//, "", $1);
- p[$4] = int($5)
- f[$4] = "'"$rootdir"'/" $1
- }
- END {
- print "<div id=\"mainmenu\"><h3><strong>Categories:</strong></h3><ul>"
-
- for (i = 1; i <= n; i++) {
- if (sel == i) print "<li class=\"selected-maincat\"><a href=\"" f[c[i]] "\">»" c[i] "«</a></li>"
- else print "<li><a href=\"" f[c[i]] "\"> " c[i] " </a></li>";
- }
-
- print "</ul></div>"
- }' -
+ grep '##WEBIF:' $cgidir/.categories $cgidir/*.sh 2>/dev/null | \
+ awk -v "selected=$1" \
+ -v "rootdir=$rootdir" \
+ -v "indexpage=$indexpage" \
+ -f /usr/lib/webif/categories.awk -
}
subcategories() {
- grep -H "##WEBIF:name:$1:" $cgidir/*.sh 2>/dev/null | sed -e 's,^.*/\([a-zA-Z\.\-]*\):\(.*\)$,\2:\1,' | sort -n | awk -F: '
- BEGIN {
- print "<div id=\"submenu\"><h3><strong>Sub-Categories:</strong></h3><ul>"
- }
- {
- if ($5 ~ /^'"$2"'$/) print "<li class=\"selected-maincat\"><a href=\"'"$rootdir/"'" $6 "\">»" $5 "«</a></li>"
- else print "<li><a href=\"'"$rootdir/"'" $6 "\"> " $5 " </a></li>"
- }
- END {
- print "</ul></div>"
- }
- ' -
+ grep -H "##WEBIF:name:$1:" $cgidir/*.sh 2>/dev/null | \
+ sed -e 's,^.*/\([a-zA-Z\.\-]*\):\(.*\)$,\2:\1,' | \
+ sort -n | \
+ awk -v "selected=$2" \
+ -v "rootdir=$rootdir" \
+ -f /usr/lib/webif/subcategories.awk -
}
update_changes() {
}
header() {
- ERROR=${ERROR:+<h3>$ERROR</h3><br /><br />}
- SAVED=${SAVED:+: Settings saved}
+ empty "$ERROR" && {
+ _saved_title="${SAVED:+: Settings saved}"
+ } || {
+ FORM_submit="";
+ ERROR="<h3>$ERROR</h3><br /><br />"
+ _saved_title=": Settings not saved"
+ }
+
_category="$1"
_uptime="$(uptime)"
_loadavg="${_uptime#*load average: }"
_hostname=$(cat /proc/sys/kernel/hostname)
_version=$(cat /etc/banner | grep "(")
_version="${_version%% ---*}"
- _saved_title=${ERROR:+: Settings not saved}
- _saved_title=${_saved_title:-$SAVED}
_head="${3:+<div class=\"settings-block-title\"><h2>$3$_saved_title</h2></div>}"
_form="${5:+<form enctype=\"multipart/form-data\" action=\"$5\" method=\"post\"><input type="hidden" name="submit" value="1" />}"
_savebutton="${5:+<p><input type=\"submit\" name=\"action\" value=\"Save changes\" /></p>}"
$_head
$ERROR
EOF
- [ -z "$REMOTE_USER" \
- -a "${SCRIPT_NAME#/cgi-bin/}" != "webif.sh" ] && {
- [ -z $FORM_passwd1 ] || {
+ empty "$REMOTE_USER" && equal "${SCRIPT_NAME#/cgi-bin/}" "webif.sh" && {
+ empty "$FORM_passwd" && {
echo '<pre>'
(
echo "$FORM_passwd1"
}
display_form() {
- echo "$1" | awk -F'|' -f /usr/lib/webif/form.awk
+ echo "$1" | awk -F'|' -f /usr/lib/webif/common.awk -f /usr/lib/webif/form.awk
}
list_remove() {
}
handle_list() {
- _new="${1:+$(list_remove "$LISTVAL" "$1") }"
- _new="${_new:-$LISTVAL}"
- LISTVAL="$_new"
- LISTVAL="${LISTVAL# }"
- LISTVAL="${LISTVAL%% }"
+ # $1 - remove
+ # $2 - add
+ # $3 - submit
+ # $4 - validate
- _validate="$4"
- _validate="${4:-none}"
- _changed="$1"
- [ \! -z "$3" ] && validate "$_validate|$2" && {
- LISTVAL="$LISTVAL $2"
- _changed="$1$3"
+ empty "$1" || {
+ LISTVAL="$(list_remove "$LISTVAL" "$1") "
+ LISTVAL="${LISTVAL# }"
+ LISTVAL="${LISTVAL%% }"
+ _changed=1
+ }
+
+ empty "$3" || {
+ validate "${4:-none}|$2" && {
+ LISTVAL="$LISTVAL $2"
+ _changed=1
+ }
}
- _return="${_changed:+0}"
- _return="${_return:-255}"
LISTVAL="${LISTVAL# }"
LISTVAL="${LISTVAL%% }"
LISTVAL="${LISTVAL:- }"
- return $_return
+
+ if empty "$_changed"; then
+ return 255
+ else
+ return 0
+ fi
}
load_settings() {
eval "$(echo "$1" | awk -f /usr/lib/webif/validate.awk)"
}
+
save_setting() {
mkdir -p /tmp/.webif
oldval=$(eval "echo \${$2}")
grep -v "^$2=" /tmp/.webif/config-$1-old > /tmp/.webif/config-$1 2>&-
oldval=""
}
- [ "$oldval" != "$3" ] && echo "$2=\"$3\"" >> /tmp/.webif/config-$1
+ equal "$oldval" "$3" || echo "$2=\"$3\"" >> /tmp/.webif/config-$1
rm -f /tmp/.webif/config-$1-old
}
-# common awk code for forms
-AWK_START_FORM='
- print "<div class=\"settings\">"
- print "<div class=\"settings-title\"><h3><strong>" title "</strong></h3></div>"
- print "<div class=\"settings-content\">"
-'
-AWK_END_FORM='
- print "</div>"
- if (form_help != "") form_help = "<dl>" form_help "</dl>"
- print "<div class=\"settings-help\"><blockquote><h3><strong>Short help:</strong></h3>" form_help form_help_link "</blockquote></div>"
- form_help = ""
- form_help_link = ""
- print "<div style=\"clear: both\"> </div></div>"
-'
-
save)
header $FORM_cat . "Configuration: updating..."
CHANGES=""
- echo '<pre>'
+ echo "<pre>"
sh /usr/lib/webif/apply.sh
- echo '</pre>'
- echo "${FORM_prev:+<meta http-equiv=\"refresh\" content=\"2; URL=$FORM_prev\" />}"
+ echo "</pre>${FORM_prev:+<meta http-equiv=\"refresh\" content=\"2; URL=$FORM_prev\" />}"
;;
esac
ETHERS_FILE=/tmp/.webif/file-ethers
}
-[ ! -z "$FORM_add_host" ] && {
+empty "$FORM_add_host" || {
# add a host to /etc/hosts
validate "ip|FORM_host_ip|IP Address|required|$FORM_host_ip
hostname|FORM_host_name|Hostname|required|$FORM_host_name" && update_hosts add "$FORM_host_ip" "$FORM_host_name"
}
-[ ! -z "$FORM_add_dhcp" ] && {
+empty "$FORM_add_dhcp" || {
# add a host to /etc/ethers
validate "mac|FORM_dhcp_mac|MAC Address|required|$FORM_dhcp_mac
ip|FORM_dhcp_ip|IP|required|$FORM_dhcp_ip" && update_ethers add "$FORM_dhcp_mac" "$FORM_dhcp_ip"
}
-[ ! -z "$FORM_remove_host" ] && update_hosts del "$FORM_remove_ip" "$FORM_remove_name"
-[ ! -z "$FORM_remove_dhcp" ] && update_ethers del "$FORM_remove_mac"
+empty "$FORM_remove_host" || update_hosts del "$FORM_remove_ip" "$FORM_remove_name"
+empty "$FORM_remove_dhcp" || update_ethers del "$FORM_remove_mac"
header "Network" "Hosts" "Configured hosts" ''
# Hosts in /etc/hosts
-# FIXME: move formatting code in form.awk if possible
-awk -v "url=$SCRIPT_NAME" '
-BEGIN {
- FS="[ \t]"
- title = "Hostnames"
- '"$AWK_START_FORM"'
- print "<table width=\"70%\" summary=\"Settings\">"
- print "<tr><th>IP</th><th>Hostname</th><th></th></tr>"
- print "<tr><td colspan=\"3\"><hr class=\"separator\" /></td></tr>"
-}
-
-# only for valid IPv4 addresses
-($1 ~ /^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$/) {
- gsub(/#.*$/, "");
- output = ""
- names_found = 0
- n = split($0, names, "[ \t]")
- first = 1
- for (i = 2; i <= n; i++) {
- if (names[i] != "") {
- if (first != 1) output = output "<tr>"
- output = output "<td>" names[i] "</td><td align=\"right\" width=\"10%\"><a href=\"" url "?remove_host=1&remove_ip=" $1 "&remove_name=" names[i] "\">Remove</a></td></tr>"
- first = 0
- names_found++
- }
- }
- if (names_found > 0) {
- print "<tr><td rowspan=\"" names_found "\">" $1 "</td>" output
- print "<tr><td colspan=\"3\"><hr class=\"separator\" /></td></tr>"
- }
-}
-
-END {
- print "<form enctype=\"multipart/form-data\" method=\"post\">"
- print "<tr><td><input type\"text\" name=\"host_ip\" value=\"'"$FORM_host_ip"'\" /></td><td><input type=\"text\" name=\"host_name\" value=\"'"$FORM_host_name"'\" /></td><td style=\"width: 10em\"><input type=\"submit\" name=\"add_host\" value=\"Add\" /></td></tr>"
- print "</form>"
- print "</table>"
- '"$AWK_END_FORM"'
-}
-' $HOSTS_FILE
+awk -v "url=$SCRIPT_NAME" \
+ -v "ip=$FORM_host_ip" \
+ -v "name=$FORM_host_name" -f /usr/lib/webif/common.awk -f /usr/lib/webif/display-hosts.awk $HOSTS_FILE
# Static DHCP mappings (/etc/ethers)
-# FIXME: move formatting code in form.awk if possible
-awk -v "url=$SCRIPT_NAME" '
-BEGIN {
- FS="[ \t]"
- title = "Static IP addresses (for DHCP)"
- '"$AWK_START_FORM"'
- print "<form enctype=\"multipart/form-data\" method=\"post\">"
- print "<table width=\"70%\" summary=\"Settings\">"
- print "<tr><th>MAC address</th><th>IP</th><th></th></tr>"
-}
-
-# only for valid MAC addresses
-($1 ~ /^[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]$/) {
- gsub(/#.*$/, "");
- print "<tr><td>" $1 "</td><td>" $2 "</td><td align=\"right\" width=\"10%\"><a href=\"" url "?remove_dhcp=1&remove_mac=" $1 "\">Remove</a></td></tr>"
-}
-
-END {
- print "<tr><td><input type\"text\" name=\"dhcp_mac\" value=\"'"$FORM_dhcp_mac"'\" /></td><td><input type=\"text\" name=\"dhcp_ip\" value=\"'"$FORM_dhcp_ip"'\" /></td><td style=\"width: 10em\"><input type=\"submit\" name=\"add_dhcp\" value=\"Add\" /></td></tr>"
- print "</table>"
- print "</form>"
- '"$AWK_END_FORM"'
-}
-' - < $ETHERS_FILE
+awk -v "url=$SCRIPT_NAME" \
+ -v "mac=$FORM_dhcp_mac" \
+ -v "ip=$FORM_dhcp_ip" -f /usr/lib/webif/common.awk -f /usr/lib/webif/display-dhcp.awk $ETHERS_FILE
footer ?>
<!--
<?
. /usr/lib/webif/webif.sh
category=$FORM_cat
-[ -z "$category" ] && category=Info
+empty "$category" && category=Info
header $category 1
-?>
-<? footer ?>
+
+footer ?>
}
FORM_dnsadd=${FORM_dnsadd:-192.168.1.1}
-
-if [ -z "$FORM_submit" -o \! -z "$ERROR" ]; then
+if empty "$FORM_submit"; then
FORM_lan_ipaddr=${lan_ipaddr:-$(nvram get lan_ipaddr)}
FORM_lan_netmask=${lan_netmask:-$(nvram get lan_netmask)}
FORM_lan_gateway=${lan_gateway:-$(nvram get lan_gateway)}
-else
+else
SAVED=1
validate "
ip|FORM_lan_ipaddr|LAN IP|required|$FORM_lan_ipaddr
load_settings system
load_settings nvram
-[ -z $FORM_submit ] && {
+if empty "$FORM_submit"; then
FORM_hostname=${wan_hostname:-$(nvram get wan_hostname)}
FORM_hostname=${FORM_hostname:-OpenWrt}
grep BCM947 /proc/cpuinfo 2>&- >&- && {
FORM_boot_wait=${boot_wait:-$(nvram get boot_wait)}
FORM_boot_wait=${FORM_boot_wait:-off}
}
-} || {
+else
SAVED=1
validate "hostname|FORM_hostname|Hostname|nodots required|$FORM_hostname" && {
save_setting system wan_hostname $FORM_hostname
esac
}
}
-}
+fi
header "System" "Settings" "System settings" '' "$SCRIPT_NAME"
end_form"
footer ?>
+
<!--
##WEBIF:name:System:1:Settings
-->
rm $FORM_firmware
}
-[ -z "$FORM_submit" -o -z "$FORM_firmware" ] || {
+empty "$FORM_submit" || empty "$FORM_firmware" || {
[ -n $FORM_firmware ] && {
HEADER=$(head -c4 $FORM_firmware | hexdump -e "8/1 \"%x\"")
grep BCM947 /proc/cpuinfo > /dev/null && {
}
}
?>
-<?if [ -z "$UPGRADE" ] ?>
+<?if empty "$UPGRADE" ?>
<form method="POST" name="upgrade" action="<? echo -n $SCRIPT_NAME ?>" enctype="multipart/form-data">
<table style="width: 90%; text-align: left;" border="0" cellpadding="2" cellspacing="2" align="center">
<tbody>
FORM_dnsadd=${FORM_dnsadd:-192.168.1.1}
-[ -z $FORM_submit ] && {
+if empty "$FORM_submit"; then
FORM_wan_proto=${wan_proto:-$(nvram get wan_proto)}
case "$FORM_wan_proto" in
# supported types
redial=${ppp_demand:-$(nvram get ppp_demand)}
case "$redial" in
- 1|enabled|on)
- FORM_ppp_redial="demand"
- ;;
- *)
- FORM_ppp_redial="persist"
- ;;
+ 1|enabled|on) FORM_ppp_redial="demand";;
+ *) FORM_ppp_redial="persist";;
esac
FORM_pptp_server_ip=${pptp_server_ip:-$(nvram get pptp_server_ip)}
-} || {
+else
SAVED=1
- [ -z $FORM_wan_proto ] && {
+ empty "$FORM_wan_proto" && {
ERROR="No WAN protocol selected"
- return -1
+ return 255
}
case "$FORM_wan_proto" in
# Settings specific to one protocol type
case "$FORM_wan_proto" in
- static)
- save_setting network wan_gateway $FORM_wan_gateway
- ;;
- pptp)
- save_setting network pptp_server_ip "$FORM_pptp_server_ip"
- ;;
+ static) save_setting network wan_gateway $FORM_wan_gateway ;;
+ pptp) save_setting network pptp_server_ip "$FORM_pptp_server_ip" ;;
esac
# Common settings for PPTP, Static and DHCP
- [ "$FORM_wan_proto" = "pptp" -o "$FORM_wan_proto" = "static" -o "$FORM_wan_proto" = "dhcp" ] && {
- save_setting network wan_ipaddr $FORM_wan_ipaddr
- save_setting network wan_netmask $FORM_wan_netmask
- }
+ case "$FORM_wan_proto" in
+ pptp|static|dhcp)
+ save_setting network wan_ipaddr $FORM_wan_ipaddr
+ save_setting network wan_netmask $FORM_wan_netmask
+ ;;
+ esac
# Common PPP settings
- [ "$FORM_wan_proto" = "pppoe" -o "$FORM_wan_proto" = "pptp" ] && {
- [ -z $FORM_ppp_username ] || save_setting network ppp_username $FORM_ppp_username
- [ -z $FORM_ppp_passwd ] || save_setting network ppp_passwd $FORM_ppp_passwd
-
- # These can be blank
- save_setting network ppp_idletime $FORM_ppp_idletime
- save_setting network ppp_redialperiod $FORM_ppp_redialperiod
- save_setting network ppp_mtu $FORM_ppp_mtu
-
- case "$FORM_ppp_redial" in
- demand)
- save_setting network ppp_demand 1
- ;;
- persist)
- save_setting network ppp_demand ""
- ;;
- esac
- }
+ case "$FORM_wan_proto" in
+ pppoe|pptp)
+ empty "$FORM_ppp_username" || save_setting network ppp_username $FORM_ppp_username
+ empty "$FORM_ppp_passwd" || save_setting network ppp_passwd $FORM_ppp_passwd
+
+ # These can be blank
+ save_setting network ppp_idletime "$FORM_ppp_idletime"
+ save_setting network ppp_redialperiod "$FORM_ppp_redialperiod"
+ save_setting network ppp_mtu "$FORM_ppp_mtu"
+
+ case "$FORM_ppp_redial" in
+ demand)
+ save_setting network ppp_demand 1
+ ;;
+ persist)
+ save_setting network ppp_demand ""
+ ;;
+ esac
+ ;;
+ esac
}
-}
+fi
header "Network" "WAN" "WAN settings" ' onLoad="modechange()" ' "$SCRIPT_NAME"
?>
"
done
-if [ -z "$FORM_submit" -o \! -z "$ERROR" ]; then
+
+if empty "$FORM_submit"; then
FORM_mode=${wl0_mode:-$(nvram get wl0_mode)}
infra=${wl0_infra:-$(nvram get wl0_infra)}
case "$infra" in
FORM_tkip=tkip
;;
esac
- [ $FORM_encryption = off ] && {
+ equal "$FORM_encryption" off && {
wep=${wl0_wep:-$(nvram get wl0_wep)}
case "$wep" in
1|enabled|on) FORM_encryption=wep;;
FORM_key=${key:-1}
else
SAVED=1
- [ "$FORM_encryption" = "wpa" ] && V_RADIUS="required"
- [ "$FORM_encryption" = "psk" ] && V_PSK="required"
+ case "$FORM_encryption" in
+ wpa) V_RADIUS="required";;
+ psk) V_PSK="required";;
+ esac
+
validate "
ip|FORM_radius_ipaddr|RADIUS IP address|$V_RADIUS|$FORM_radius_ipaddr
wep|FORM_key1|WEP key 1||$FORM_key1
string|FORM_radius_key|RADIUS server key|min=4 max=63 $V_RADIUS|$FORM_radius_key
string|FORM_ssid|ESSID|required|$FORM_ssid
int|FORM_channel|Channel|required min=1 max=$CHANNEL_MAX|$FORM_channel" && {
- case "$FORM_mode" in
- adhoc)
- save_setting wireless wl0_mode sta
- save_setting wireless wl0_infra 0
- ;;
- *)
- save_setting wireless wl0_mode "$FORM_mode"
- save_setting wireless wl0_infra 1
- ;;
- esac
+
+ if equal "$FORM_mode" adhoc; then
+ FORM_mode=sta
+ infra="0"
+ fi
+ save_setting wireless wl0_mode "$FORM_mode"
+ save_setting wireless wl0_infra ${infra:-1}
save_setting wireless wl0_ssid "$FORM_ssid"
save_setting wireless wl0_channel "$FORM_channel"
- case "$FORM_aes$FORM_tkip" in
- aes) save_setting wireless wl0_crypto aes;;
- tkip) save_setting wireless wl0_crypto tkip;;
- aestkip) save_setting wireless wl0_crypto tkip+aes;;
- esac
+
+ crypto=""
+ equal "$FORM_aes" aes && crypto="aes"
+ equal "$FORM_tkip" tkip && crypto="tkip${crypto:++$crypto}"
+
case "$FORM_encryption" in
psk)
case "${FORM_wpa1}${FORM_wpa2}" in
fi
header "Network" "Wireless" "Wireless settings" ' onLoad="modechange()" ' "$SCRIPT_NAME"
-?>
+
+cat <<EOF
<script type="text/javascript" src="/webif.js"></script>
<script type="text/javascript">
<!--
-->
</script>
-<? display_form "start_form|Wireless Configuration
+EOF
+
+display_form "start_form|Wireless Configuration
field|ESSID
text|ssid|$FORM_ssid
helpitem|ESSID